var BaseTelModify = app.controller('BaseTelModify', function($rootScope,$scope,$http,BaseTelModifyData) {
	try{
		$rootScope.showf=false;
		$scope.show = false;
		$scope.busy = false;
		$rootScope.code_value = '获取验证码';
		$rootScope.title = '验证手机';

		$scope.keyPress=function(e){
			console.log(e);
			if(e.which==13){
				$scope.settel();
			}
		}
		$scope.keyPressNext=function(e){
			console.log(e);
			if(e.which==13||e.which==9){
				$scope.settel();
			}
		}
		// 设置新手机
		$scope.dobusy = false;
		$scope.settel = function() {
			if($scope.dobusy){
				return false;
			}
			
			if($scope.tel == ""){
				showtoast("请输入手机号码");
				return false;
			}
			
			var reg = /(^13\d{9}$)|(^14)[5,7]\d{8}$|(^15[0,1,2,3,5,6,7,8,9]\d{8}$)|(^17)[6,7,8]\d{8}$|(^18\d{9}$)/g ;  
		    if(!reg.test($scope.tel)){  
		    	showtoast("请输入正确的手机");
				return false;
		    } 
			
			if(!$scope.validate_code){
				showtoast("请输入验证码");
				return false;
			}

			$scope.dobusy=true;
			var url=SITE_URL+"index.php?app=usermyapp&act=modifytel&tel="+$scope.tel+"&callback=JSON_CALLBACK&code="+$scope.validate_code;
			$http.jsonp(url).success(function(data) {
				if(data.done){
					showtoast("手机验证成功！");
					$rootScope.autologin();
					$rootScope.back();	
				}else{
					$scope.dobusy = false;
				}
			}).error(function(){$scope.dobusy = false;});
		};

		$scope.get_code=function(){
			if($scope.busy){
				return false;
			}
			var reg = /(^13\d{9}$)|(^14)[5,7]\d{8}$|(^15[0,1,2,3,5,6,7,8,9]\d{8}$)|(^17)[6,7,8]\d{8}$|(^18\d{9}$)/g ;  
		    if(!reg.test($scope.tel)){  
		    	showtoast("请输入正确的手机");
				return false;
		    } 
			$scope.busy=true;
			var url=SITE_URL+"index.php?app=userapp&act=authcode&t="+$scope.tel+"&callback=JSON_CALLBACK&type=resetphone";
			$http.jsonp(url).success(function(data) {
				if(data.done){
					
					$scope.code_num = 60;
					$rootScope.code_value = '秒后重发';
					var myTime = setInterval(function() {
						$scope.code_num--;
						$scope.$apply(); // 通知视图模型的变化

						if($scope.code_num<=0){

							$scope.busy=false;
							$rootScope.code_value = '获取验证码';
							$scope.code_num =  '';
							clearInterval(myTime);
							$scope.$apply();
						}
					}, 1000);	
				}else{
					$scope.busy=false;
					return false;
				}
			}).error(function(){$scope.busy = false;});
		}
	}
	catch (e) {
		showcatch(e);
	}
});
BaseTelModify.BaseTelModifyData=function($q, $http,$stateParams,$rootScope){
	try {
		var data = [];
		var def = $q.defer();
		if(window.localStorage.u==undefined||window.localStorage.u==null||window.localStorage.u==""){			
			$rootScope.go("loginmain");
		}else{
			def.resolve(data);
		}
		
		return def.promise;
	} catch (e) {
		showcatch(e);
	}
}